package com.turtle.learning.users.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.turtle.learning.users.entity.User;
import com.turtle.learning.users.mapper.UserMapper;
import com.turtle.learning.users.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 分享 服务实现类
 *
 * @author turtle
 * @since 2020-04-29
 */
@Service
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    private final UserMapper userMapper;

    /**
     * 通过登录账号获取用户信息
     *
     * @param username 用户账号
     * @return User
     */
    @Override
    public User getUserByUsername(String username) {

        QueryWrapper<User> userWrapper = new QueryWrapper<>();
        userWrapper.lambda().eq(User::getUsername, username);
        User user = userMapper.selectOne(userWrapper);
        if (user == null) {
            throw new IllegalArgumentException("请求用户不存在");
        }
        return user;
    }

}
